﻿#Region "License & Usage"

'Microsoft Public License (Ms-PL) 

'This license governs use of the accompanying software. If you use the 
'software, you accept this license. If you do not accept the license, do 
'not use the software. 

'1. Definitions 

'The terms "reproduce," "reproduction," "derivative works," and 
'"distribution" have the same meaning here as under U.S. copyright law. 

'A "contribution" is the original software, or any additions or changes 
'to the software. 

'A "contributor" is any person that distributes its contribution under 
'this license. 

'"Licensed patents" are a contributor's patent claims that read directly 
'on its contribution. 

'2. Grant of Rights 

'(A) Copyright Grant- Subject to the terms of this license, including the 
'license conditions and limitations in section 3, each contributor grants 
'you a non-exclusive, worldwide, royalty-free copyright license to 
'reproduce its contribution, prepare derivative works of its 
'contribution, and distribute its contribution or any derivative works 
'that you create. 

'(B) Patent Grant- Subject to the terms of this license, including the 
'license conditions and limitations in section 3, each contributor grants 
'you a non-exclusive, worldwide, royalty-free license under its licensed 
'patents to make, have made, use, sell, offer for sale, import, and/or 
'otherwise dispose of its contribution in the software or derivative 
'works of the contribution in the software. 

'3. Conditions and Limitations 

'(A) No Trademark License- This license does not grant you rights to use 
'any contributors' name, logo, or trademarks. 

'(B) If you bring a patent claim against any contributor over patents 
'that you claim are infringed by the software, your patent license from 
'such contributor to the software ends automatically. 

'(C) If you distribute any portion of the software, you must retain all 
'copyright, patent, trademark, and attribution notices that are present 
'in the software. 

'(D) If you distribute any portion of the software in source code form, 
'you may do so only under this license by including a complete copy of 
'this license with your distribution. If you distribute any portion of 
'the software in compiled or object code form, you may only do so under a 
'license that complies with this license. 

'(E) The software is licensed "as-is." You bear the risk of using it. The 
'contributors give no express warranties, guarantees or conditions. You 
'may have additional consumer rights under your local laws which this 
'license cannot change. To the extent permitted under your local laws, 
'the contributors exclude the implied warranties of merchantability, 
'fitness for a particular purpose and non-infringement.

#End Region

#Region "Options"

Option Strict On
Option Explicit On

#End Region

#Region "Imports"

'From .Net Framework 3.5
Imports Microsoft.Drawing
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms

'From Custom Classes/Reference
Imports StedySoft.SenseSDK
Imports StedySoft.SenseSDK.DrawingCE
Imports SenseSDKExtended.DrawingCEEx

#End Region

Namespace SensePanelPictureBox

    ''' <summary>SensePanelPictureBox.Style1</summary>
    ''' <author>Greenhacks</author>
    ''' <author-reference>None</author-reference>
    ''' <copyright>None</copyright>
    ''' <version>0.1</version>
    ''' <remarks>None</remarks>
    ''' <reference>None</reference>
    Public Class Style1
        Inherits SensePanelBase
        Implements IDisposable


#Region "Fields"

        'General Flags
        Private _disposed As Boolean = False

        'General Properties
        Private _name As String = Nothing

        'Image properties
        Private _iimage As IImage = Nothing
        Private _iimageSize As Size = Nothing
        Private _iimageAlignment As StringAlignment = StringAlignment.Center
        Private _iimageLineAlignment As StringAlignment = StringAlignment.Center

        Private _iimageRectangle As Rectangle = Nothing

#End Region

#Region "Methods"

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <remarks>None</remarks>
        Public Sub New()

            Try

                'Do Nothing

            Catch ex As Exception

                'Throw exception if any other error caught
                Throw New Exception(ex.Message)

            End Try

        End Sub

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <remarks>None</remarks>
        Public Sub New(ByVal Name As String)

            Try

                'Save name property
                _name = Name

            Catch ex As Exception

                'Throw exception if any other error caught
                Throw New Exception(ex.Message)

            End Try

        End Sub

        ''' <summary>
        ''' Dispose
        ''' </summary>
        ''' <remarks>None</remarks>
        Public Overrides Sub Dispose()

            Try

                Me._dispose(True)
                GC.SuppressFinalize(Me)
                MyBase.Dispose()

            Catch ex As Exception

                'Throw exception if any other error caught
                Throw New Exception(ex.Message)

            End Try

        End Sub

        ''' <summary>
        ''' _Dispose
        ''' </summary>
        ''' <param name="disposing"></param>
        ''' <remarks>None</remarks>
        Private Sub _dispose(ByVal disposing As Boolean)

            Try

                Me._disposed = True

            Catch ex As Exception

                'Throw exception if any other error caught
                Throw New Exception(ex.Message)

            End Try
        End Sub

        ''' <summary>
        ''' Check if it is VGA or QVGA
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function _isVGA() As Boolean

            Try

                'Return the output
                Return StedySoft.SenseSDK.DrawingCE.Resolution.ScreenIsVGA

            Catch ex As Exception

                'Throw exception if any other error caught
                Throw New Exception(ex.Message)

            End Try

        End Function

        ''' <summary>
        ''' OnRender
        ''' </summary>
        ''' <param name="g"></param>
        ''' <remarks></remarks>
        Public Overrides Sub OnRender(ByVal g As System.Drawing.Graphics)
            MyBase.OnRender(g)

            Dim __iimageX As Integer = Nothing
            Dim __iimageY As Integer = Nothing
            Dim __iimageW As Integer = _iimageSize.Width
            Dim __iimageH As Integer = _iimageSize.Height

            Select Case _iimageAlignment

                Case StringAlignment.Near
                    _iimageRectangle = New Rectangle(CInt(ClientRectangle.Left), CInt(ClientRectangle.Top), __iimageW, __iimageH)
                Case StringAlignment.Center
                    _iimageRectangle = New Rectangle(CInt((Screen.PrimaryScreen.Bounds.Width - _iimageSize.Width) / 2), CInt(ClientRectangle.Top), __iimageW, __iimageH)
                Case StringAlignment.Far
                    _iimageRectangle = New Rectangle(Screen.PrimaryScreen.Bounds.Width - _iimageSize.Width, CInt(ClientRectangle.Top), __iimageW, __iimageH)

            End Select

            Dim __iimage As IImage = _iimage
            g.DrawImageAlphaChannel(__iimage, New Rectangle(_iimageRectangle.Left, _iimageRectangle.Top, _iimageRectangle.Width, _iimageRectangle.Height))

        End Sub

#End Region

#Region "Properties"

        ''' <summary>
        ''' Image
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <CLSCompliant(False)> _
        Public Property Image() As IImage
            Get
                Return _iimage
            End Get
            Set(ByVal value As IImage)
                _iimage = value
            End Set
        End Property

        ''' <summary>
        ''' ImageSize
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ImageSize() As Size
            Get
                Return _iimageSize
            End Get
            Set(ByVal value As Size)
                _iimageSize = value
            End Set
        End Property

        ''' <summary>
        ''' ImageAlignment
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ImageAlignment() As StringAlignment
            Get
                Return _iimageAlignment
            End Get
            Set(ByVal value As StringAlignment)
                _iimageAlignment = value
            End Set
        End Property

        ''' <summary>
        ''' ImageLineAlignment
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ImageLineAlignment() As StringAlignment
            Get
                Return _iimageLineAlignment
            End Get
            Set(ByVal value As StringAlignment)
                _iimageLineAlignment = value
            End Set
        End Property

#End Region

    End Class

End Namespace